package cn.kgc.tangcco.tcbd1011.booktype.action;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.kgc.tangcco.tcbd1011.booktype.entity.BookType;
import cn.kgc.tangcco.tcbd1011.booktype.services.BookTypeService;
import cn.kgc.tangcco.tcbd1011.comm.base.BaseServlet;
import cn.kgc.tangcco.tcbd1011.comm.properties.PropertiesFactory;
import cn.kgc.tangcco.tcbd1011.util.MyBeanUtils;
import cn.kgc.tangcco.tcbd1011.util.Util;


/**
 * Servlet implementation class BookServlet
 */
@WebServlet(name="BookTypeServlet",urlPatterns="/bookType.action")
public class BookTypeServlet extends BaseServlet {
	private BookTypeService	 bookTypeService=(BookTypeService) PropertiesFactory.getInstance(Util.BOOKTYPESERVICE);
	public static final String SUCCESS="bookType.action?methodName=doListBook";
	
	
	public String doListBook(HttpServletRequest request,HttpServletResponse response) {
		String forward="book/listBookType";
		request.setAttribute("blist", bookTypeService.queryAllBook());
		return forward;
	}
	public String toAddBook(HttpServletRequest request,HttpServletResponse response) {
		String forward="book/addBookType";
		request.setAttribute("blist", bookTypeService.queryAllBook());
		return forward;
	}
	public String doAddBook(HttpServletRequest request,HttpServletResponse response) {
		String forward=SUCCESS;
		BookType book=MyBeanUtils.populate(BookType.class, request.getParameterMap());
		request.setAttribute("rows", bookTypeService.addBookType(book));
		return forward;
	}
	public String detailBook(HttpServletRequest request,HttpServletResponse response) {
		String forward="book/detailBookType";
		request.setAttribute("books", bookTypeService.queryTypeToBooks());
		request.setAttribute("book", bookTypeService.detailBookTypeById(Util.parseInt(request.getParameter("typeid"))));
		return forward;
	}
	public String toUpdateBook(HttpServletRequest request,HttpServletResponse response) {
		String forward="book/updateBookType";
		request.setAttribute("book", bookTypeService.detailBookTypeById(Util.parseInt(request.getParameter("typeid"))));
		return forward;
	}
	public String doUpdateBook(HttpServletRequest request,HttpServletResponse response) {
		String forward=SUCCESS;
		request.setAttribute("rows", bookTypeService.updateBookType(MyBeanUtils.populate(BookType.class, request.getParameterMap())));
		return forward;
	}
	

}
